package com.kvest.mobile_newspaper.android;

import java.io.File;
import java.util.ArrayList;

import com.kvest.mobile_newspaper.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class FileBrowserListAdapter extends ArrayAdapter<File>
{
	private ArrayList<File> items;
	private LayoutInflater inflater;
	
	public FileBrowserListAdapter(Context context, int textViewResourceId, ArrayList<File> items) 
    {
        super(context, textViewResourceId, items);
        this.inflater = LayoutInflater.from(context);
        this.items = items;
    }
	
	@Override
    public View getView(int position, View convertView, ViewGroup parent) 
    {
    	View view = convertView;
        if (view == null) 
        {
        	view = this.inflater.inflate(R.layout.file_row, null);
        }
        File element = items.get(position);
        TextView fileName = (TextView) view.findViewById(R.id.file_name);
          
        if (element != null && fileName != null) 
        {
        	fileName.setText((element.isDirectory() ? "/" : "") + element.getName());
        }
        return view;
    }
}
